home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / tests / case.test < prev    next >
Text File  |  1992-11-06  |  3KB  |  87 lines

  1. # Commands covered:  case
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /user6/ouster/tcl/tests/RCS/case.test,v 1.6 92/07/06 09:49:20 ouster Exp $ (Berkeley)
  17.  
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. test case-1.1 {simple pattern} {
  21.     case a in a {format 1} b {format 2} c {format 3} default {format 4}
  22. } 1
  23. test case-1.2 {simple pattern} {
  24.     case b a {format 1} b {format 2} c {format 3} default {format 4}
  25. } 2
  26. test case-1.3 {simple pattern} {
  27.     case x in a {format 1} b {format 2} c {format 3} default {format 4}
  28. } 4
  29. test case-1.4 {simple pattern} {
  30.     case x a {format 1} b {format 2} c {format 3}
  31. } {}
  32. test case-1.5 {simple pattern matches many times} {
  33.     case b a {format 1} b {format 2} b {format 3} b {format 4}
  34. } 2
  35. test case-1.6 {fancier pattern} {
  36.     case cx a {format 1} *c {format 2} *x {format 3} default {format 4}
  37. } 3
  38. test case-1.7 {list of patterns} {
  39.     case abc in {a b c} {format 1} {def abc ghi} {format 2}
  40. } 2
  41.  
  42. test case-2.1 {error in executed command} {
  43.     list [catch {case a in a {error "Just a test"} default {format 1}} msg] \
  44.         $msg $errorInfo
  45. } {1 {Just a test} {Just a test
  46.     while executing
  47. "error "Just a test""
  48.     ("a" arm line 1)
  49.     invoked from within
  50. "case a in a {error "Just a test"} default {format 1}"}}
  51. test case-2.2 {error: not enough args} {
  52.     list [catch {case} msg] $msg
  53. } {1 {wrong # args: should be "case string ?in? patList body ... ?default body?"}}
  54. test case-2.3 {error: pattern with no body} {
  55.     list [catch {case a b} msg] $msg
  56. } {1 {extra case pattern with no body}}
  57. test case-2.4 {error: pattern with no body} {
  58.     list [catch {case a in b {format 1} c} msg] $msg
  59. } {1 {extra case pattern with no body}}
  60. test case-2.5 {error in default command} {
  61.     list [catch {case foo in a {error case1} default {error case2} \
  62.         b {error case 3}} msg] $msg $errorInfo
  63. } {1 case2 {case2
  64.     while executing
  65. "error case2"
  66.     ("default" arm line 1)
  67.     invoked from within
  68. "case foo in a {error case1} default {error case2}         b {error case 3}"}}
  69.  
  70. test case-3.1 {single-argument form for pattern/command pairs} {
  71.     case b in {
  72.     a {format 1}
  73.     b {format 2}
  74.     default {format 6}
  75.     }
  76. } {2}
  77. test case-3.2 {single-argument form for pattern/command pairs} {
  78.     case b {
  79.     a {format 1}
  80.     b {format 2}
  81.     default {format 6}
  82.     }
  83. } {2}
  84. test case-3.3 {single-argument form for pattern/command pairs} {
  85.     list [catch {case z in {a 2 b}} msg] $msg
  86. } {1 {extra case pattern with no body}}
  87.